package com.hd.openapi.web.cotenollen;

import com.hd.openapi.common.Const;
import com.hd.openapi.common.ResultTable;
import com.hd.openapi.entity.AdminUser;
import com.hd.openapi.entity.Menu;
import com.hd.openapi.entity.Role;
import com.hd.openapi.servies.pageroleser;
import com.hd.openapi.servies.servies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

import com.hd.openapi.common.ResponseResult;

@RestController
@RequestMapping("/user")
public class cotan {
    @Autowired
    private servies a;
    @Autowired
    private pageroleser ser;

    @RequestMapping("/dl")
    public ResponseResult dl(HttpSession session,String email,String password){
        AdminUser getdataall = a.getdataall (email, password);
        System.out.println (email);
        if (getdataall!=null) {
            session.setAttribute (Const.IS_LOGIN,getdataall);
            return ResponseResult.getSuccess ();
        }
        return null;
    }

    @RequestMapping("/tuic")
    public void tuil(HttpSession session, HttpServletResponse response) throws IOException {
        session.invalidate ();
        response.sendRedirect ("/login.html");
    }
    @RequestMapping("/table")
    public ResultTable table(@RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "5") Integer limit,
                             String realName, String email, Integer status){
    return a.getadminuserdata(page,limit,realName,email,status);
    }
    @RequestMapping("/del")
    public ResponseResult delete(Integer[] ids){
        return a.deletedata(ids);
    }
    @RequestMapping("/add")
    public ResponseResult add(AdminUser adminUser){
        return a.add(adminUser);
    }
    @RequestMapping("/updae")
    public ResponseResult update(AdminUser adminUser){
        return a.updatedata(adminUser);
    }
    //查询指定id的权限
    @RequestMapping("/uarole")
    public List<Integer> urole(Integer userId){ return a.getdatauserid(userId); }
    @RequestMapping("/rtree")
    public List<Menu> rtree(){
        return ser.getmenualldata ();
    }
    @RequestMapping("/arole")
    public ResponseResult arole(){
        return null;
    }


}
